package com.yiwei.zxp.fragment;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.LoginNewActivity;
import com.yiwei.zxp.activity.RegisterActivity;
import com.yiwei.zxp.util.ToastUtil;
import com.yiwei.zxp.util.UI;
import com.yiwei.zxp.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTextChanged;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 18-5-17.
 */

public class LoginPhoneFragment extends BaseFragment {
    @BindView(R.id.edit_phone)
    EditText editPhone;
    @BindView(R.id.btn_submit)
    TextView btnSubmit;
    @BindView(R.id.btn_register)
    TextView btnRegister;


    @Override
    protected int setLayoutId() {
        return R.layout.fragment_login_phone;
    }

    @Override
    protected void initView() {

    }

    @OnTextChanged(R.id.edit_phone)
    void afterTextChanged(Editable s) {
        if (TextUtils.isEmpty(UI.toString(editPhone))) {
            btnSubmit.setSelected(false);
        } else {
            if (UI.toString(editPhone).length() == 11) {
                btnSubmit.setSelected(true);
            } else {
                btnSubmit.setSelected(false);
            }
        }
    }



    @OnClick({R.id.btn_submit, R.id.btn_register, R.id.btn_clear})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_submit:
                if (TextUtils.isEmpty(UI.toString(editPhone))) {
                    ToastUtil.makeText(getActivity(), "手机号不能为空");
                    return;
                }
                ((LoginNewActivity) getActivity()).getSmsSend(UI.toString(editPhone));
                break;
            case R.id.btn_register:
                Util.startActivity(getActivity(), RegisterActivity.class);
                break;
            case R.id.btn_clear:
                editPhone.setText("");
                break;
        }
    }
}
